// 清空用户名输入框
document.getElementById('clearUsername').addEventListener('click', function() {
    document.getElementById('username').value = '';
});


// 切换密码显示/隐藏
document.getElementById('togglePassword').addEventListener('click', function() {
    const passwordInput = document.getElementById('password');
    if (passwordInput.type === 'password') {
        passwordInput.type = 'text';
        this.innerHTML = '🙉';
    } else {
        passwordInput.type = 'password';
        this.innerHTML = '🙈';
    }
});

// 显示消息提示
function showMessage(message, type) {
    const messageBox = document.getElementById('message');
    messageBox.textContent = message;
    messageBox.style.display = 'block';

    // 2秒后自动隐藏消息
    setTimeout(function() {
        messageBox.style.display = 'none';
    }, 2000);
}

// 输入框聚焦时显示清空按钮
document.getElementById('username').addEventListener('focus', function() {
    if (this.value) {
        document.getElementById('clearUsername').style.display = 'block';
    }
});

document.getElementById('username').addEventListener('input', function() {
    if (this.value) {
        document.getElementById('clearUsername').style.display = 'block';
    } else {
        document.getElementById('clearUsername').style.display = 'none';
    }
});

document.getElementById('password').addEventListener('focus', function() {
    if (this.value) {
        document.getElementById('clearPassword').style.display = 'block';
    }
});

document.getElementById('password').addEventListener('input', function() {
    if (this.value) {
        document.getElementById('clearPassword').style.display = 'block';
    } else {
        document.getElementById('clearPassword').style.display = 'none';
    }
});